//index.js
//获取应用实例
const app = getApp()
const DB = wx.cloud.database()
Page({
  data: {
    //轮播图数据
    swiperList: [
      {_id: 0, type: 'image', img_url: '/assets/image/1.jpg'}
      ],
    cardCur: 0,
  },
  //轮播图改变事件
  cardSwiper(e) {
    this.setData({
      cardCur: e.detail.current
    })
  },
  //个人预约点击事件
  goOrder() {
    wx.navigateTo({
      url: '/pages/order/order'
    })
  },
  //我的预约点击事件
  goMyOrder() {
    wx.navigateTo({
      url: '/pages/myOrder/myOrder'
    })
  },
  //校园导览点击事件
  goMap() {
    wx.navigateTo({
      url: '/pages/map/map'
    })
  },
  //校园美景点击事件
  goImage() {
    wx.navigateTo({
      url: '/pages/image/image'
    })
  },
  //校园店铺点击事件
  goVR() {
    wx.navigateTo({
      url: '/pages/vrCX/vrCX'
    })
  },
  //参观须知点击事件
  goNotice() {
    wx.navigateTo({
      url: '/pages/notice/notice'
    })
  },
  //校园介绍点击事件
  goDesc() {
    wx.navigateTo({
      url: '/pages/introduce/introduce'
    })
  },
  //使用帮助点击事件
  goHelp() {
    wx.navigateTo({
      url: '/pages/help/help'
    })
  },




  

  onLoad: function () {
    this.getSwiper()
  },
  getSwiper() {
    //获取轮播图数据
    DB.collection("swiper_image").get({
      success: (res) => {
        this.setData({
          swiperList: res.data,
          cardCur: res.data[0]._id
        })
      },
      fail: (res) => {
        wx.showModal({
          title: '失败',
          content: '获取录播图失败,请重试',
          showCancel: false,
          confirmText: '重试',
          success:(res) => {
            if (res.confirm) {
              return this.getSwiper
            } 
          }
        })
      }
    })
  }
})
